#include "thread.h"
#include "clamp.h"
#include "backHelixes.h"
#include "../framework.h"

const float Thread::fixSpeed = 2.5f;
Vertexf Thread::vertices[] = { Vertexf(0,-0.5f),Vertexf(0,0.5f)};

Thread::Thread(Rectangle rec,Rectangle recClamp):SceneObject(rec){
    this->objVertices.vertices=vertices;
    this->objVertices.nVertices=nVertices;
    this->addObject(Clamp::name(),new Clamp(recClamp));
}

Thread::~Thread(){}

void Thread::draw(){
    Framework& fr = Framework::instance();
	Colorf oldColor = fr.pipeline.getLineColor();
	fr.pipeline.pushMatrix();
		fr.pipeline.pushMatrix();
			fr.pipeline.translate(dimensions.centerX(), dimensions.centerY());
			fr.pipeline.escale(dimensions.width(),dimensions.height());
			fr.pipeline.setLineColor(Colorf(0.3f,0.3f,0.0f));
			fr.pipeline.draw(Pipeline::LINES,this->objVertices.vertices,this->objVertices.nVertices);
		fr.pipeline.popMatrix();
		(this->findObject(Clamp::name())).draw();
	fr.pipeline.popMatrix();
    fr.pipeline.setLineColor(oldColor);
}

void Thread::timeStep(){
    (this->findObject(Clamp::name())).timeStep();
}

void Thread::moveClamp(MotionVector dir){
	this->dimensions.y2+=Thread::fixSpeed*dir;
	(this->findObject(Clamp::name())).move(0.0f,Thread::fixSpeed*dir);
}

void Thread::closeClamp(){
	Clamp& clamp=dynamic_cast<Clamp&>(this->findObject(Clamp::name()));
	clamp.close();
}

void Thread::openClamp(){
	Clamp& clamp=dynamic_cast<Clamp&>(this->findObject(Clamp::name()));
	clamp.open();
}

